package com.ssm.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.pojo.address.Address;
import com.ssm.pojo.address.AddressDeleteOrDefualtResponseParameter;
import com.ssm.pojo.address.AddressList;
import com.ssm.pojo.address.AddressRequestParameter;
import com.ssm.pojo.address.AddressResponseParameter;
import com.ssm.service.AddressService;
 

@Controller
public class AddressController {
	  @Autowired
	  AddressService addressService;
	 
	  // 收货地址列表
	  @RequestMapping(value="addressList")
	  public String list() {
			return "address/addressList";
	  }
	  
	  // 添加收货地址
	  @RequestMapping(value="addressAdd")
	  public String add() {
		    return "address/addressAdd";
	  }	
	  
	  // 编辑收货地址
	  @RequestMapping(value="addressEdit",method = RequestMethod.POST)
	  public String edit(int id,ModelMap m) {
		    Address edit = addressService.get(id);
		    m.addAttribute("edit", edit);
			return "address/addressEdit";
	  }
	  
	  // 获取常用收货地址
	  @RequestMapping(value="/api/v1/user/get/contect",method = RequestMethod.POST)
	  @ResponseBody
	  public Address get(int id){
		return addressService.get(id);
	  }	  

	  // 获取收货地址列表 API
	  @RequestMapping(value="/api/v1/contect",method = RequestMethod.POST)
	  @ResponseBody
	  public AddressList list(int id) {
		 return addressService.list(id);
	  }
	  
	  // 删除常用收获地址列表 API
	  // /api/v1/user/remove/contect
	  @RequestMapping(value="/api/v1/user/remove/contect",method = RequestMethod.POST)
	  @ResponseBody
	  public AddressDeleteOrDefualtResponseParameter delete(AddressRequestParameter data) {
		 return addressService.delete(data);
	  }
	  
	  // 新增常用收获地址 API
	  // /api/v1/user/add/contect
	  @RequestMapping(value="/api/v1/user/add/contect",method = RequestMethod.POST)
	  @ResponseBody
	  public AddressResponseParameter add(Address address){
		return addressService.add(address);
	  }
	  
	  // 修改常用收货地址 API
	  // /api/v1/user/update/contect
	  @RequestMapping(value="/api/v1/user/update/contect",method = RequestMethod.POST)
	  @ResponseBody
	  public AddressResponseParameter update(Address address){
		return addressService.update(address);
	  }
	  
	  // 设置默认收货地址 API
	  // /api/v1/user/contect/default
	  @RequestMapping(value="/api/v1/user/contect/default",method = RequestMethod.POST)
	  @ResponseBody
	  public AddressDeleteOrDefualtResponseParameter defaultAddr(AddressRequestParameter data) {
		return addressService.defaultAddr(data);
	  }
	  
}